package interviewclassic;

/**
 * @author ZhanBo
 * @date 2020/7/12
 */
public class Solution1601 {
    public static void main(String[] args) {
        swapNumbers(new int[]{3,4});
    }

    /**
     * 面试题 16.01. 交换数字
     * 编写一个函数，不用临时变量，直接交换numbers = [a, b]中a与b的值。
     * 输入: numbers = [1,2]
     * 输出: [2,1]
     * @param numbers
     * @return
     */
    public static int[] swapNumbers(int[] numbers) {
        numbers[0] = numbers[0] - numbers[1];
        numbers[1] = numbers[0] + numbers[1];
        numbers[0] = numbers[1] - numbers[0];
        return numbers;
    }
}
